package models

import (
	"time"

	"gorm.io/gorm"
)

// SequenceRule 编号规则模型
type SequenceRule struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	Code        string    `gorm:"type:varchar(50);uniqueIndex;not null;comment:规则编码" json:"code"`
	Name        string    `gorm:"type:varchar(100);not null;comment:规则名称" json:"name"`
	Prefix      string    `gorm:"type:varchar(20);not null;comment:前缀" json:"prefix"`
	DateFormat   string    `gorm:"type:varchar(20);default:'YYYYMMDD';comment:日期格式" json:"date_format"`
	SequenceLen  int       `gorm:"default:6;comment:序号长度" json:"sequence_len"`
	ResetType    string    `gorm:"type:varchar(20);default:'never';comment:重置类型:never(从不),daily(每日),monthly(每月),yearly(每年)" json:"reset_type"`
	CurrentSeq   int       `gorm:"default:0;comment:当前序号" json:"current_seq"`
	LastDate     *time.Time `gorm:"comment:最后生成日期" json:"last_date"`
	Status       string    `gorm:"type:varchar(20);default:'active';comment:状态:active(启用),inactive(停用)" json:"status"`
	Description  string    `gorm:"type:varchar(255);comment:描述" json:"description"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"index" json:"-"`
}

// TableName 指定表名
func (SequenceRule) TableName() string {
	return "sequence_rules"
}

